//
// Copyright (c) 2009 All Right Reserved
//
// vl
//
// 2018-12-01
// Contains ...
namespace LargoPanels.Editor
{
using LargoCommon.Interfaces;
using LargoCommon.Music;
using System;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Xml.Linq;
///
/// Interact logic for LineCell.
///
public class VoiceCell : BaseCell
{
#region Constructors
///
/// Initializes a new instance of the VoiceCell class.
///
/// The given master.
/// The given voice.
public VoiceCell(LineSpace givenMaster, IAbstractVoice givenVoice) : base(givenMaster) {
if (givenVoice == null) {
var instrument = new MusicalInstrument(MidiMelodicInstrument.StringEnsemble1);
var octave = MusicalOctave.OneLine;
var loudness = MusicalLoudness.MeanLoudness;
this.Voice = new MusicalVoice {
Instrument = instrument, Octave = octave, Loudness = loudness
};
return;
}
this.Voice = givenVoice;
this.LineIndex = givenVoice.Line.LineIndex;
}
#endregion
#region Main Properties
///
/// Gets or sets the voice.
///
///
/// The voice.
///
public IAbstractVoice Voice { get; set; }
#endregion
#region Properties - Xml
///
/// Gets the X element.
///
/// Returns value.
public XElement GetXElement {
get {
var xstatus = new XElement("Status", null);
xstatus.Add(new XAttribute("Octave", this.Voice.Octave));
xstatus.Add(new XAttribute("Loudness", this.Voice.Loudness));
var instr = this.Voice.Instrument ?? new MusicalInstrument(MidiMelodicInstrument.None);
xstatus.Add(instr.GetXElement);
return xstatus;
}
}
#endregion
#region Public methods - Set Xml
///
/// Sets the X element.
///
/// The element.
public void SetXElement(XElement xelement) { //// MusicalHeader givenHeader
Contract.Requires(xelement != null);
var attribute = xelement.Attribute("Octave");
if (attribute != null) {
this.Voice.Octave = DataEnums.ReadAttributeMusicalOctave(attribute);
}
attribute = xelement.Attribute("Loudness");
if (attribute != null) {
this.Voice.Loudness = DataEnums.ReadAttributeMusicalLoudness(attribute);
}
var xinstrument = xelement.Element("Instrument");
if (xinstrument != null) {
this.Voice.Instrument = new MusicalInstrument(xinstrument); //// : null;
//// 2016 DataEnums.ReadAttributeMidiMelodicInstrument(xelement.Attribute("MelodicInstrument"));
}
}
#endregion
#region Public methods
/// Gets or sets the formatted text.
/// The formatted text.
public override FormattedText FormattedText() {
var sb = new StringBuilder();
sb.AppendFormat("{0}/ {1} {2}\n", this.LineIndex, this.Voice.Octave, this.Voice.Loudness);
sb.Append(this.Voice.Instrument);
var ft = Abstract.AbstractText.Singleton.FormatText(sb.ToString(), (int)this.Width - SeedSize.BasicMargin);
return ft;
}
#endregion
#region Copy-Paste
///
/// Copies this instance.
///
public override void Copy() {
StringBuilder sb = new StringBuilder();
var xstatus = this.Voice.GetXElement;
var item = xstatus.ToString();
sb.AppendFormat("{0};", item);
Clipboard.SetText(sb.ToString());
//// Clipboard.SetDataObject(xstatus);
Console.Beep(880, 180);
}
///
/// Pastes this instance.
///
public override void Paste() {
var s = Clipboard.GetText();
if (string.IsNullOrEmpty(s)) {
return;
}
var splitArray = s.Split(';');
if (!splitArray.Any()) {
return;
}
var item = splitArray.First();
//// var xstatus = XElement.Parse(item);
//// this.voice
Console.Beep(990, 180);
}
#endregion
}
}